home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / Feelin021015 / Libs / Feelin / Bar.c < prev    next >
C/C++ Source or Header  |  2002-10-28  |  7KB  |  262 lines

  1. ;/*
  2.    Avail Flush >NIL:
  3.    MakeClass Bar VER 1 REV 00 ;ASM
  4.    Quit
  5. */
  6.  
  7. ///Header
  8. #include <libraries/feelin.h>
  9.  
  10. #include <clib/utility_protos.h>
  11. #include <clib/exec_protos.h>
  12. #include <clib/dos_protos.h>
  13. #include <clib/graphics_protos.h>
  14. #include <clib/feelin_protos.h>
  15.  
  16. #include <pragmas/exec_pragmas.h>
  17. #include <pragmas/dos_pragmas.h>
  18. #include <pragmas/graphics_pragmas.h>
  19. #include <pragmas/utility_pragmas.h>
  20.  
  21. UBYTE FCC_Name[] = FC_Bar;
  22. UBYTE FCC_ID[]   = "$VER: FC_Bar 1.00 (11-06-00) by Olivier Laviale (lotan9@aol.com)";
  23.  
  24. struct Library       *DOSBase,*GfxBase,*UtilityBase;
  25. struct FeelinBase    *FeelinBase;
  26.  
  27. struct LocalObjectData
  28. {
  29.    STRPTR                         pcTitle;
  30.    STRPTR                         pcPreParse;
  31. //   struct FeelinTextDisplay         TD;
  32.    APTR                             TD;
  33.    UWORD                           nFlags;
  34.    UWORD                           nReserved;
  35. // FP_Xxx
  36.    ULONG                           nPref_PreParse;
  37. };
  38.  
  39. #define FF_Bar_Vertical (1L << 00)
  40. //+
  41.  
  42. /*** Methods ***************************************************************/
  43.  
  44. ///Bar.New
  45. ULONG SAVEDS bar_New(struct FeelinClass *Class,APTR Obj,struct LocalObjectData *LOD,struct TagItem *Tags)
  46. {
  47.    struct TagItem *item;
  48.  
  49.    LOD -> nPref_PreParse = FP_Bar_PreParse;
  50.  
  51.    if (F_SuperDoA(Class,Obj,FM_New,(ULONG *)Tags))
  52.    {
  53.       while (item = NextTagItem(&Tags))
  54.       {
  55.          switch (item -> ti_Tag)
  56.          {
  57.             case FA_Bar_Title:      LOD -> pcTitle    = (STRPTR)item -> ti_Data; break;
  58.             case FA_Bar_PreParse:   LOD -> pcPreParse = (STRPTR)item -> ti_Data; break;
  59.          }
  60.       }
  61.  
  62.       if (LOD -> pcTitle)
  63.       {
  64.          if (LOD -> TD = F_NewObjA(FC_TextDisplay,NULL))
  65.          {
  66.             F_Set(LOD -> TD,FA_TextDisplay_Contents,(ULONG)LOD -> pcTitle);
  67.          }
  68.          else
  69.          {
  70.             return NULL;
  71.          }
  72.       }
  73.       return (ULONG)Obj;
  74.    }
  75.  
  76.    return NULL;
  77. }
  78. //+
  79. ///Bar.Dispose
  80. ULONG SAVEDS bar_Dispose(struct FeelinClass *Class,APTR Obj,struct LocalObjectData *LOD)
  81. {
  82.    LOD -> TD = (APTR) F_DisposeObj((APTR)LOD -> TD);
  83.    return F_SuperDoA(Class,Obj,FM_Dispose,NULL);
  84. }
  85. //+
  86. ///Bar.Get
  87. ULONG SAVEDS bar_Get(struct LocalObjectData *LOD,struct TagItem *Tags)
  88. {
  89.    struct TagItem *item;
  90.    ULONG  *save;
  91.  
  92.    while (item = NextTagItem(&Tags))
  93.    {
  94.       save = (ULONG *)item -> ti_Data;
  95.  
  96.       switch (item -> ti_Tag)
  97.       {
  98.          case FA_Bar_Title:      *save = (ULONG)LOD -> pcTitle;    break;
  99.          case FA_Bar_PreParse:   *save = (ULONG)LOD -> pcPreParse; break;
  100.       }
  101.    }
  102.    return NULL;
  103. }
  104. //+
  105. ///Bar.Setup
  106. ULONG SAVEDS bar_Setup(struct FeelinClass *Class,APTR Obj,struct LocalObjectData *LOD,ULONG *pnArgs)
  107. {
  108.    ULONG data;
  109.  
  110.    if (F_SuperDoA(Class,Obj,FM_Setup,pnArgs))
  111.    {
  112.       if (LOD -> TD)
  113.       {
  114.          data = (ULONG)"`l`Ss`Sh"; // Default
  115.          F_Do(_client(Obj),FM_Client_Resolve,(ULONG)LOD -> nPref_PreParse,(ULONG)&data);
  116.          LOD -> pcPreParse = (STRPTR)data;
  117.  
  118.          F_Do(LOD -> TD,FM_Set,
  119.                         FA_TextDisplay_PreParse, (ULONG)LOD -> pcPreParse,
  120.                         FA_TextDisplay_Font,     (ULONG)_font(Obj),
  121.                         TAG_DONE);
  122.       }
  123.       return TRUE;
  124.    }
  125.    return FALSE;
  126. }
  127. //+
  128. ///Bar.Cleanup
  129. ULONG SAVEDS bar_Cleanup(struct FeelinClass *Class,APTR Obj,struct LocalObjectData *LOD,ULONG *pnArgs)
  130. {
  131.    F_Do(LOD -> TD,FM_Set,
  132.                   FA_Text_PreParse,     NULL,
  133.                   FA_TextDisplay_Font,  NULL, TAG_DONE);
  134.  
  135.    return F_SuperDoA(Class,Obj,FM_Cleanup,pnArgs);
  136. }
  137. //+
  138. ///Bar.AskMinMax
  139. ULONG SAVEDS bar_AskMinMax(struct FeelinClass *Class,struct FeelinObject *Obj,struct LocalObjectData *LOD)
  140. {
  141.    LOD -> nFlags = F_Get(Obj -> Parent,FA_Horizontal) ? LOD -> nFlags | FF_Bar_Vertical : LOD -> nFlags - (LOD ->nFlags & FF_Bar_Vertical);
  142.  
  143.    if (LOD -> TD)
  144.    {
  145.       if ((LOD -> nFlags & FF_Bar_Vertical) == FALSE)
  146.       {
  147.          _minh(Obj) += ((struct FeelinTextDisplay *)(LOD -> TD)) -> nHeight;
  148.       }
  149.    }
  150.    else
  151.    {
  152.       if (LOD -> nFlags & FF_Bar_Vertical)
  153.       {
  154.          _minw(Obj) += 2;
  155.          _maxw(Obj)  = _minw(Obj);
  156.       }
  157.       else
  158.       {
  159.          _minh(Obj) += 2;
  160.          _maxh(Obj)  = _minh(Obj);
  161.       }
  162.    }
  163.    return F_SuperDoA(Class,Obj,FM_AskMinMax,NULL);
  164. }
  165. //+
  166. ///Bar.Draw
  167. ULONG SAVEDS bar_Draw(struct FeelinClass *Class,APTR Obj,struct LocalObjectData *LOD,ULONG *pnArgs)
  168. {
  169.    struct RastPort           *rp;
  170.    struct FeelinTextDisplay  *td;
  171.    struct FeelinRect          rect;
  172.    ULONG  dark,shine;
  173.    UWORD  x1,y1,x2,y2,w,h, bw;
  174.    
  175.    rp = _rp(Obj);
  176.    x1 = _x(Obj); w = _w(Obj); x2 = x1 + w - 1; dark  = _pen(Obj,FV_Pen_Dark);
  177.    y1 = _y(Obj); h = _h(Obj); y2 = y1 + h - 1; shine = _pen(Obj,FV_Pen_Shine);
  178.  
  179.    F_SuperDoA(Class,Obj,FM_Draw,pnArgs);
  180.  
  181.    if (LOD -> nFlags & FF_Bar_Vertical)
  182.    {
  183.       if (w > 2) x1 = w / 2 + x1 - 1;
  184.  
  185.       _APen(dark);  _Move(x1,y1);   _Draw(x1,y2);
  186.       _APen(shine); _Move(x1+1,y1); _Draw(x1+1,y2);
  187.    }
  188.    else
  189.    {
  190.       if (td = LOD -> TD)
  191.       {
  192.          rect.x1 = x1+10+1; rect.y1 = y1;
  193.          rect.x2 = x2-10-1; rect.y2 = y2;
  194.  
  195.          if (F_Do(td,FM_TextDisplay_Size,&rect) == 0) goto __done;
  196.  
  197.          bw = (w - 10 - td -> nWidth) / 2;
  198.          y1 = (h / 2) + y1;
  199.  
  200.          _APen(shine); _Move(x1,y1);   _Draw(x1+bw-1,y1);   _Move(x2-bw+1,y1);   _Draw(x2,y1);
  201.          _APen(dark);  _Move(x1,y1-1); _Draw(x1+bw-1,y1-1); _Move(x2-bw+1,y1-1); _Draw(x2,y1-1);
  202.  
  203.          rect.x1 = x1+bw+5; rect.x2 = x2-bw-5;
  204.  
  205.          F_Do(td,FM_TextDisplay_Draw,&rect,_render(Obj));
  206.       }
  207.       else
  208.       {
  209. __done:
  210.          if (h > 2) y1 = h / 2 + y1 - 1;
  211.  
  212.          _APen(dark);  _Move(x1,y1);   _Draw(x2,y1);
  213.          _APen(shine); _Move(x1,y1+1); _Draw(x2,y1+1);
  214.       }
  215.    }
  216.    return NULL;
  217. }
  218. //+
  219.  
  220. /*** Class *****************************************************************/
  221.  
  222. ///FCC_Dispatcher
  223. ULONG SAVEDS ASM FCC_Dispatcher(REG_A2 struct FeelinClass *Class,REG_A0 APTR Obj,REG_D0 ULONG Method,REG_A1 ULONG *Args)
  224. {
  225.    struct LocalObjectData *LOD = INST_DATA(Class,Obj);
  226.  
  227.    switch (Method)
  228.    {
  229.       case FM_New:         return bar_New        (Class,Obj,LOD,(struct TagItem *)Args);
  230.       case FM_Dispose:     return bar_Dispose    (Class,Obj,LOD);
  231.       case FM_Get:                F_SuperDoA     (Class,Obj,Method,Args);
  232.                            return bar_Get        (LOD,(struct TagItem *)Args);
  233.  
  234.       case FM_Setup:       return bar_Setup      (Class,Obj,LOD,Args);
  235.       case FM_Cleanup:     return bar_Cleanup    (Class,Obj,LOD,Args);
  236.       case FM_AskMinMax:   return bar_AskMinMax  (Class,Obj,LOD);
  237.       case FM_Draw:        return bar_Draw       (Class,Obj,LOD,Args);
  238.  
  239.       default:             return F_SuperDoA     (Class,Obj,Method,Args);
  240.    }
  241. }
  242. //+
  243. ///FCC_Info
  244. ULONG * SAVEDS ASM FCC_Info(REG_A0 struct FeelinBase *Feelin)
  245. {
  246.    static ULONG Tags[] =
  247.    {
  248.       FA_SuperID,    (ULONG)FC_Area,
  249.       FA_DataSize,   sizeof(struct LocalObjectData),
  250.       FA_Dispatcher, (ULONG)FCC_Dispatcher,
  251.       TAG_DONE
  252.    };
  253.  
  254.    FeelinBase  = Feelin;
  255.    DOSBase     = Feelin -> Dos;
  256.    GfxBase     = Feelin -> Graphics;
  257.    UtilityBase = Feelin -> Utility;
  258.  
  259.    return Tags;
  260. }
  261. //+
  262.